Skip to content

[rb] trim whitespace around NO_PROXY entries#17565

Open
aguspe wants to merge 3 commits into
SeleniumHQ:trunkfrom
aguspe:rb-trim-no-proxy-whitespace
Open

[rb] trim whitespace around NO_PROXY entries#17565
aguspe wants to merge 3 commits into
SeleniumHQ:trunkfrom
aguspe:rb-trim-no-proxy-whitespace

Conversation

@aguspe
Copy link
Copy Markdown
Contributor

@aguspe aguspe commented May 24, 2026

🔗 Related Issues

#17460

💥 What does this PR do?

This commit fixes the bug #17460 where NO_PROXY / no_proxy entries were parsed without trimming surrounding whitespace, so values like localhost, 127.0.0.1 would not match the target host and Selenium would not bypass the proxy as expected. I also updated the tests.

🔧 Implementation Notes

Two sites were splitting no_proxy differently:

  • remote/http/default.rb used split(',') without trimming, so entries with leading spaces never matched the server host.
  • common/proxy.rb#as_json used split(', '), which failed for comma-only separated values like proxy_url,localhost.

Both now use split(',').map(&:strip).reject(&:empty?) so the parsing is consistent and tolerant of surrounding whitespace.

🔄 Types of changes

  • Bug fix (backwards compatible)

@selenium-ci selenium-ci added the C-rb Ruby Bindings label May 24, 2026
@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Trim whitespace around NO_PROXY entries in Ruby

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix NO_PROXY parsing to trim whitespace around entries
• Standardize no_proxy splitting across two Ruby files
• Handle both comma-separated and comma-space-separated formats
• Add comprehensive test coverage for whitespace handling
Diagram
flowchart LR
  A["NO_PROXY string with whitespace"] -->|split and trim| B["Clean array of hosts"]
  B -->|proxy matching logic| C["Correct proxy bypass decision"]
  D["common/proxy.rb"] -->|updated parsing| B
  E["remote/http/default.rb"] -->|updated parsing| B

Loading

File Changes

1. rb/lib/selenium/webdriver/common/proxy.rb 🐞 Bug fix +1/-1

Standardize no_proxy parsing with whitespace trimming

• Changed no_proxy string splitting from split(', ') to
 split(',').map(&:strip).reject(&:empty?)
• Handles both comma-only and comma-space-separated formats consistently
• Removes empty entries after splitting and trimming

rb/lib/selenium/webdriver/common/proxy.rb


2. rb/lib/selenium/webdriver/remote/http/default.rb 🐞 Bug fix +1/-1

Add whitespace trimming to proxy bypass logic

• Updated use_proxy? method to trim whitespace from no_proxy entries
• Changed from split(',') to split(',').map(&:strip).reject(&:empty?)
• Ensures consistent parsing with common/proxy.rb

rb/lib/selenium/webdriver/remote/http/default.rb


3. rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb 🧪 Tests +12/-0

Add no_proxy whitespace handling tests

• Added test for comma-only separated no_proxy values
• Added test for whitespace trimming around entries
• Validates that both formats are correctly converted to arrays

rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb


View more (1)
4. rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb 🧪 Tests +14/-0

Add proxy bypass whitespace trimming tests

• Added test for trimming whitespace around multiple entries
• Added test for trimming leading whitespace on single entry
• Validates proxy bypass works correctly with whitespace variations

rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review Bot commented May 24, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Context used

Grey Divider


Advisory comments

1. Array no_proxy unsupported 🐞 Bug ≡ Correctness
Description
Remote::Http::Default#use_proxy? unconditionally calls split on proxy.no_proxy, which raises
NoMethodError if no_proxy is provided as an Array. This is inconsistent with Proxy#as_json and
capabilities behavior that treat array no_proxy values as valid.
Code

rb/lib/selenium/webdriver/remote/http/default.rb[153]

Evidence
use_proxy? calls split on proxy.no_proxy without checking its type, while Proxy#as_json
explicitly supports non-String no_proxy values (e.g., arrays), and the capabilities spec asserts
array no_proxy is valid input.

rb/lib/selenium/webdriver/remote/http/default.rb[149-167]
rb/lib/selenium/webdriver/common/proxy.rb[143-159]
rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb[44-48]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`Selenium::WebDriver::Remote::Http::Default#use_proxy?` assumes `proxy.no_proxy` is a `String` and calls `.split(',')` on it. If a `Proxy` is configured with `no_proxy` as an `Array` (which other parts of the Ruby bindings accept), this will raise at runtime.

### Issue Context
The PR makes `Proxy#as_json` accept both comma-separated strings and arrays for `noProxy`, but the HTTP client bypass logic isn’t type-aligned.

### Fix Focus Areas
- rb/lib/selenium/webdriver/remote/http/default.rb[149-167]

### Implementation sketch
- Normalize `proxy.no_proxy` into a `hosts` array via:
 - `String`: `split(',').map(&:strip).reject(&:empty?)`
 - `Array`: `map(&:to_s).map(&:strip).reject(&:empty?)`
 - else: treat as empty
- Run `.any?` over `hosts` instead of calling `.split` directly.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit d7c4046

Results up to commit 92ddd47


🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)


Advisory comments
1. Array no_proxy unsupported 🐞 Bug ≡ Correctness
Description
Remote::Http::Default#use_proxy? unconditionally calls split on proxy.no_proxy, which raises
NoMethodError if no_proxy is provided as an Array. This is inconsistent with Proxy#as_json and
capabilities behavior that treat array no_proxy values as valid.
Code

rb/lib/selenium/webdriver/remote/http/default.rb[153]

Evidence
use_proxy? calls split on proxy.no_proxy without checking its type, while Proxy#as_json
explicitly supports non-String no_proxy values (e.g., arrays), and the capabilities spec asserts
array no_proxy is valid input.

rb/lib/selenium/webdriver/remote/http/default.rb[149-167]
rb/lib/selenium/webdriver/common/proxy.rb[143-159]
rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb[44-48]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`Selenium::WebDriver::Remote::Http::Default#use_proxy?` assumes `proxy.no_proxy` is a `String` and calls `.split(',')` on it. If a `Proxy` is configured with `no_proxy` as an `Array` (which other parts of the Ruby bindings accept), this will raise at runtime.

### Issue Context
The PR makes `Proxy#as_json` accept both comma-separated strings and arrays for `noProxy`, but the HTTP client bypass logic isn’t type-aligned.

### Fix Focus Areas
- rb/lib/selenium/webdriver/remote/http/default.rb[149-167]

### Implementation sketch
- Normalize `proxy.no_proxy` into a `hosts` array via:
 - `String`: `split(',').map(&:strip).reject(&:empty?)`
 - `Array`: `map(&:to_s).map(&:strip).reject(&:empty?)`
 - else: treat as empty
- Run `.any?` over `hosts` instead of calling `.split` directly.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review Bot commented May 24, 2026

Persistent review updated to latest commit ec1c324

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review Bot commented May 25, 2026

Persistent review updated to latest commit d7c4046

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-rb Ruby Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants